package edu.uc.labs.MobilePrinting.GUI;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class PreferencesFrame extends JFrame implements ActionListener {

	private static final long serialVersionUID = -2051525508610402431L;

	public PreferencesFrame() {
		// Name the window
		super("Mobile Printing Preferences");
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);

		// Set up the close/cancel button
		closeButton = new JButton();
		closeButton.addActionListener(this);
		closeButton.setActionCommand("Close");
		closeButton.setText("Cancel");

		// Set up the save button
		saveButton = new JButton();
		saveButton.addActionListener(this);
		saveButton.setActionCommand("Save");
		saveButton.setText("Save");

		// Set up the defaults button
		defaultsButton = new JButton();
		defaultsButton.addActionListener(this);
		defaultsButton.setActionCommand("Defaults");
		defaultsButton.setText("Restore Defaults");

		// Setup the button pane
		JPanel buttonPane = new JPanel();
		buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
		buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
		buttonPane.add(Box.createHorizontalGlue());
		buttonPane.add(defaultsButton);
		buttonPane.add(Box.createRigidArea(new Dimension(200, 0)));
		buttonPane.add(closeButton);
		buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
		buttonPane.add(saveButton);

		// Place the button near the bottom of the window.
		Container contentPane = getContentPane();
		contentPane.add(buttonPane, BorderLayout.PAGE_END);

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		
		if ("Close".equals(e.getActionCommand())) {
			// if the close button was clicked...
			setVisible(false);
			dispose();
		}

		if ("Save".equals(e.getActionCommand())) {
			// the save button was clicked
			
		}

		if ("Defaults".equals(e.getActionCommand())) {
			// the defaults button was clicked
		}
	}

	public void addCloseButton() {
		Container contentPane = getContentPane();
		contentPane.add(closeButton);
		closeButton.setAlignmentX(Component.CENTER_ALIGNMENT); // horizontally
																// centered
	}

	public void addSaveButton() {
		Container contentPane = getContentPane();
		contentPane.add(saveButton);
		saveButton.setAlignmentX(Component.CENTER_ALIGNMENT);

	}

	// Variable Declaration
	JButton closeButton;
	JButton saveButton;
	JButton defaultsButton;
}
